|
|
|
|
|
|
|
'LOCKS EVERY TEXT BOX ON THE FORM
Dim objControl As Control
For Each objControl In Me.Controls
If TypeOf objControl Is TextBox Then objControl.Locked = True
Next objControl |
|
|
|
|
|
|
|
|
From a user interface standpoint, the Locked property allows you to use the same screen for data entry and lookup. Locking text boxes prevents unauthorized personnel from changing information, as shown in Figure 19.8. |
|
|
|
|
|
|
|
|
Figure 19.8
Using the Locked property prevents inadvertent editing of text.
In the pop-up menu (automatically implemented by Windows),
notice that only the Copy option is available for a locked text box. |
|
|
|
|
|
|
|
|
|
Do not confuse the Locked property with the Enabled property. The Locked property does not create the grayed-out effect. Additionally, it allows the users to select and copy text from the text box, but the Enabled property does not.  |
|
|
|
|
|
|
|
|
|
|
When you're designing a data entry form, one of the tasks you must perform is data validation. One type of data validation is making sure the data entered will fit in the designated database field. For example, Social Security numbers are by definition nine digits. Although this check can be performed in VB code with the Len statement, you can avoid the extra code by using the TextBox control's MaxLength property. The MaxLength property allows you to specify the maximum number of characters that can be entered in a text box, regardless of its size on the form. |
|
|
|
|
|
|
|
|
The PasswordChar Property |
|
|
|
|
|
|
|
|
If you are using a text box as part of a login form, you will want to be able to hide the passwords entered by the users. To do so, simply enter a character in the PasswordChar property of the text box. This property changes the text box's display behavior so that the password character is displayed in place of each character in the Text property. You may have seen this effect many times when logging in to Windows. |
|
|
|
|
|
|
|
|
Note that the contents of the Text property still reflect what was actually typed by the users, and your code always sees the "real" text. Although you can enter any character, using the asterisk (*) character for hiding text is customary. |
|
|
|
|
|
|
|
|
Editing Text in a Text Box |
|
|
|
|
|
|
|
|
A standard text box allows the users to highlight text with the mouse or by using Ctrl+Shift with the cursor keys. Your code can then manipulate the selected text with the SelText, SelLength, and SelStart properties. You can use these properties to work with a selected piece of text in your program. Look at the example in Figure 19.9. In this |
|
|
|
|
|